package com.five.base.configuration;

import com.aliyun.oss.OSSClient;
import com.five.base.common.BaseAliyunOSS;
import com.five.common.util.AliyunOssUtil;
import com.five.common.util.BaseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * @ClassName AliyunOSSConfiguration
 * @Author xwu36
 * @Date 2019/1/7 13:01
 * @Version 1.0
 * @Description 阿里云上传log
 **/
@Component
@Configuration
@Slf4j
public class AliyunOssConfiguration extends BaseAliyunOSS {


    @Override
    public Boolean isUploadSuccess(){
        log.info("--------------开始上传日志---------------");
        OSSClient client = AliyunOssUtil.getOssUtil().getOSSClient(OSS_ADDRESS, KEY_ID, KEY_SECRET);
        String fileRename = BaseUtil.getBaseUtil().getStringSplit(AliyunOssUtil.getOssUtil().fileRename(LOCALFILE_ADDRESS),"/")[1];
        boolean isSuccess = AliyunOssUtil.getOssUtil().uploadByFile(client, new File(LOCALFILE_ADDRESS), BUCKET_NAME, OSSFILE_ADDRESS+fileRename);
        if (isSuccess){
            log.info("-------------日志上传成功-----------");
        }else {
            log.info("-------------日志上传失败------------");
        }
        return isSuccess;
    }

}
